<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #email {
            color: #c0c0c0;
        }
    </style>
</head>
<body>
<input type="text" id="email" value="用户名">
<input type="text" id="email2">
<script>
    var obj = document.getElementById('email');
    //focus 获得焦点
    //blur
    obj.onfocus = function(){
        if (obj.value == '用户名'){
            obj.value = '';
            obj.style.color = 'black';
        }

    };
    obj.onblur = function () {
        if (obj.value == ''){
            obj.value= '用户名'
            obj.style.color = '#c0c0c0';
        }

    }

</script>
</body>
</html>